<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-商品详情</title>
	<link rel="stylesheet" type="text/css" href="/static/css/reset.css">
	<link rel="stylesheet" type="text/css" href="/static/css/main.css">
    <script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript" src="/static/js/register.js"></script>
    <script>
        $(function () {
            if ('{{ request.session.user_id}}') {
                //如果用户登录了
                $.get('/cart/count/', function (data) {
                    $('#show_count').html(data.count);
                })
            }
        })
    </script>
</head>
<body>
	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜!</div>
			<div class="fr">

				{% if request.session.user_names %}
                    <div class="login_info fl">
					欢迎您：<em>{{ request.session.user_names }}</em>
                    <a href="/logout/">退出</a>
				    </div>
                    <div class="user_link fl">
					<span>|</span>
					<a href="/user_center_info/">用户中心</a>
					<span>|</span>
					<a href="/cart/">我的购物车</a>
					<span>|</span>
					<a href="/user_center_order/">我的订单</a>
				</div>
                {% else %}
                    <div class="login_btn fl">
					<a href="/login/">登录</a>
					<span>|</span>
					<a href="/register/">注册</a>
				    </div>
                {% endif %}
			</div>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<a href="/" class="logo fl"><img src="/static/images/logo.png"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>
		<div class="guest_cart fr">
			<a href="/cart/" class="cart_name fl">我的购物车</a>
			<div class="goods_count fl" id="show_count"> </div>
		</div>
	</div>


	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="/lists1_1_0/" class="fruit">新鲜水果</a></li>
					<li><a href="/lists2_1_0/" class="seafood">海鲜水产</a></li>
					<li><a href="/lists3_1_0/" class="meet">猪牛羊肉</a></li>
					<li><a href="/lists4_1_0/" class="egg">禽类蛋品</a></li>
					<li><a href="/lists5_1_0/" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="/lists6_1_0/" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="/">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>
{#-------------------------------------------------------------------------------------------#}
	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img src="/static/{{ gpic }}"></div>

		<div class="goods_detail_list fr">
            <input type="hidden" value="{{ gid }}" class="gid">
            <input type="hidden" value="{{ gprice }}" class="prices">
{#			<h3>大兴大棚草莓</h3>#}
			<h3>{{ gtitle }}</h3>
{#			<p>草莓浆果柔软多汁，味美爽口，适合速冻保鲜贮藏。草莓速冻后，可以保持原有的色、香、味，既便于贮藏，又便于外销。</p>#}
			<p>{{ gjianjie }}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>{{ gprice }}</em></span>
				<span class="show_unit">单  位：{{ gunit }}</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1" id="cli">
					<a href="javascript:;" class="add fr" id="add">+</a>
					<a href="javascript:;" class="minus fr" id="minus">-</a>
				</div> 
			</div>
			<div class="total">总价：<em>{{ gprice }}</em></div>
			<div class="operate_btn">
{#				<a href="#" class="buy_btn">立即购买</a>#}
                <div class="buy_btn">立即购买</div>
{#				<a href="javascript:;" class="add_cart" id="add_cart">加入购物车</a>#}
                <div class="add_cart" id="add_cart">加入购物车</div>
			</div>
		</div>
	</div>
{#-----------------------------------------------------------------------------------#}
	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="/detail_1/"><img src="/static/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="/detail_2/"><img src="/static/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd>{{ gcontent|safe }}</dd>
				</dl>
			</div>

		</div>
	</div>

	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	<div class="add_jump"></div>
    <input type="hidden" value="{{ islogins }}" class="islogins">

	<script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">

		    var $add_x = $('#add_cart').offset().top;
            var $add_y = $('#add_cart').offset().left;

            var $to_x = $('#show_count').offset().top;
            var $to_y = $('#show_count').offset().left;

            var islogins = $('.islogins').val()

		    {#小圆点初始位置#}
		    $(".add_jump").css({'left':$add_y+80,'top':$add_x+10,'display':'block'});
		    $('#add_cart').click(function(){
		        if (islogins == 1){
                    $(".add_jump").stop().animate({
                        'left': $to_y+7,
                        'top': $to_x+7},
                        "fast",
                        function() {
                            $(".add_jump").fadeOut('fast',function(){
                                {#---------------自写，改变我的购物车的数量值#}
                                let inum = $('#show_count').html();
                                let inum1 = $('#cli').val();
                                $('#show_count').html(parseInt(inum)+parseInt(inum1));
                                {#$('#show_count').html(2);#}

                                let gid = $('.gid').val();
                                $.ajax({
                                    url:'/carts/',
                                    data:{'inum1':inum1,'gid':gid},
                                    type: 'get',
                                    DataType: 'json'
                                }).done(function (res) {
                                    if (res.ccount){
                                        $('#show_count').html(res.ccount)
                                    }
                                })

                                {#让小圆点返回初始位置#}
                                $(".add_jump").css({'left':$add_y+80,'top':$add_x+10,'display':'block'});
                            });
                    });
                    }
                else{
                    alert('请先登录！');
                    window.location.href = '/login/';
                }
		    })


        {#点击事件，商品数量的+、-！#}
        $(function () {
            let prices = $('.prices').val();
            $('#add').click(function () {
                let $num = $('.num_show').val();
                $('.num_show').val(parseInt($num)+1)
                $num++
                $('.total').children('em').html(parseFloat(prices*$num).toFixed(2))
            })
            $('#minus').click(function () {
                if ($('.num_show').val() > 1){
                let $num = $('.num_show').val();
                $('.num_show').val(parseInt($num)-1);
                $num--
                $('.total').children('em').html(parseFloat(prices*$num).toFixed(2))
                }
            })
            $('.buy_btn').click(function () {
                let gid = $('.gid').val();
                let inum1 = $('#cli').val();
                $.ajax({
                    url:'/index12/',
                    type:'get',
                    data:{'gid':gid,'inum1':inum1},
                    DataType:'json',
                }).done(function (res) {
                    if (res.islogin === 1){
                        window.location.href = '/place_order1/'
                    }
                })
            })
        })

	</script>
	
</body>
</html>